package com.itheima.springboot_06_demo.controller;

import com.itheima.springboot_06_demo.pojo.Dept;
import com.itheima.springboot_06_demo.pojo.Result;
import com.itheima.springboot_06_demo.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class DeptController {

    @Autowired
    private DeptService deptService;

    // 查询所有部门
    @GetMapping("/depts")
    public Result getDeptList(){
        log.info("查询所有部门信息. . .");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }

    // 添加部门信息
    @PostMapping("/depts")
    public Result addDept(@RequestBody Dept dept){
        log.info("新增部门：{}",dept);
        deptService.add(dept);
        return Result.success();
    }
}
